#include "Master.h"
#include "MasterOwnedStates.h"


//#include "StateMachine.h"
//No Touchy Touchy Fiddle Fiddle, this be the property of Khann1bl3 yo. Comments are aight.

// *Touchys and Fiddles* ~ Durange

//Master's constructor was originally written here by K13. Deleted by Strog since it's supposed to be defined in header


//ChangeState is no longer a function of the Master class and is instead defined in StateMachine - Strog

void Master::ChangeState(State<Master>* pNewState)
{
	
	assert (pCurrentState && pNewState);	//make sure both states are both valid before attempting to call methods

	pCurrentState->Exit(this);			//call the exit method of the existing state
	pCurrentState = pNewState;			//change state to the new state
	pCurrentState->Enter(this);			//call the entry method of the new state
}

bool Master::Thirsty()
{
	if (iThirst > cimThirstFlag)
		return true;

	return false;
}

bool Master::Fatigued()
{
	if (iFatigue > cimFatigueFlag)
		return true;

	return false;
}

bool Master::Uncomfortable()
{
	if (iDiscomfort > cimDiscomfortFlag)
		return true;

	return false;
}

bool Master::Hungry()
{
	if (iHunger > cimHungerFlag)
		return true;

	return false;
}

bool Master::Wealthy()
{
	if(iPoverty <= cimPovertyFlag)
		return true;
	
	return false;
}
void Master::Update()
{
	pStateMachine->Update();
}

void Master::FindActivity()
{
	if(Wealthy())
	{
		pStateMachine->ChangeState(VisitTownAndDonate::Instance());
	}
	else if(Thirsty())
	{
		pStateMachine->ChangeState(VisitOasisAndDrink::Instance());
	}
	else if(Hungry())
	{
		pStateMachine->ChangeState(VisitJungleAndScavenge::Instance());
	}
	else if(Fatigued())
	{
		pStateMachine->ChangeState(VisitTownAndSleep::Instance());
	}
	else if(Uncomfortable())
	{
		pStateMachine->ChangeState(VisitOasisAndMeditate::Instance());
	}
	else
	{
	 pStateMachine->ChangeState(VisitTownAndWork::Instance());
	}
}

/*void Master::FindActivity()
{
	if(iPoverty >= cimPovertyFlag)
	{
		pStateMachine->ChangeState(VisitTownAndDonate::Instance());
	}
	else
	{
		int need = 10;				//checks highest need
		int needPoint = -1;			//points to needed stat
		bool check[4] = {false};	//Temp used to check flags
		int check2[4] = {10};		//Temp used to check flags

		if(iThirst >= cimThirstFlag)
		{check[0] = true;check2[0] = iThirst;}
		if(iHunger >= cimHungerFlag)
		{check[1] = true;check2[1] = iHunger;}

		if(iFatigue >= cimFatigueFlag)
		{check[2] = true;check2[2] = iFatigue;}
		if(iDiscomfort >= cimDiscomfortFlag)
		{check[3] = true;check2[3] = iDiscomfort;}

		for(int i = 0; i < 4 ; ++i)
		{
			if(check[i] = true&&check2[i] < need)
			{
				need = check2[i];
				needPoint = i;
			}
		}

		switch(needPoint)
		{

		case 0:	pStateMachine->ChangeState(VisitOasisAndDrink::Instance());
			break; 
		case 1: pStateMachine->ChangeState(VisitTownAndSleep::Instance());
			break;
		case 2: pStateMachine->ChangeState(VisitOasisAndMeditate::Instance());
			break; 
		case 3: pStateMachine->ChangeState(VisitJungleAndScavenge::Instance());
			break;
		default: pStateMachine->ChangeState(VisitTownAndWork::Instance());
		}
	}
}*/
